import { infoService, userInfoByIdService } from '@/api/front/common'

const state = {
    topNews: [],
    total: 0,
    info:{},
    infoType: [],
};
const mutations = {

    // 分页查资讯信息
    getInfoMutations(state, param) {
        state.topNews = param.data;
        state.total = param.total;
    },

    // 通过id查资讯信息
    getInfoByIdMutations(state, param) {
        state.info = param.data;
    },
};
const actions = {
    // 分页查询资讯信息
    async getInfoActions(context,params) {
        await infoService(params).then(resp => {
            if (!resp) return;
            console.log("infoRespData-->", resp.data);
            context.commit('getInfoMutations', resp.data)
        }, error => {
            console.log(error);
        })
    },

    // 通过id查询资讯信息
    async getInfoByIdActions(context, id) {
        await userInfoByIdService(id).then(resp => {
            if (!resp) return;
            console.log("infoRespData-->", resp.data);
            context.commit('getInfoByIdMutations', resp.data)
        }, error => {
            console.log(error);
        })
    },
};

export default {
    namespaced: true,
    state,
    mutations,
    actions,
}